
import { getToken, setToken, removeToken } from '@/utils/auth'
import { resetRouter } from '@/router'
import  {_API} from '@/api/bai'

const types = {

    SET_DATA_DETAIL: 'SET_DATA_DETAIL',
    SET_DATA_PEIYAO:'SET_DATA_PEIYAO',
    SET_DATA_KUCUN_DETAIL:'SET_DATA_KUCUN_DETAIL',
    SET_DATA_PEIYAODETAIL:'SET_DATA_PEIYAODETAIL',
    
}
const state = {
        dataDetail:[],  //字典客房
        dataPeiYao:[],
        dataKuCunDetail:[],
        dataPeiYaoDetail:[],
}

const mutations = {
 
  [types.SET_DATA_DETAIL]:(state, name)=> {
    state.dataDetail = name
  },
  [types.SET_DATA_PEIYAO]:(state, name)=> {
    state.dataPeiYao = name
  },
  [types.SET_DATA_KUCUN_DETAIL]:(state, name)=> {
    state.dataKuCunDetail = name
  },
  [types.SET_DATA_PEIYAODETAIL]:(state, name)=> {
    state.dataPeiYaoDetail = name
  },
  
}

const actions = {
  // user login
  getclinic_drug_houseDispenseInfo({ commit }, d){
    return new Promise((resolve, reject) => {
      _API.getclinic_drug_houseDispenseInfo(d).then((res)=>{
         
            if (res.code === 200 && res.data) {
              commit('SET_DATA_PEIYAODETAIL', res.data.map((v,i)=>{
                  return {
                    ...v,
                    
                  }
              }))
          
              resolve(res)
           
          } else {
              commit('SET_DATA_PEIYAODETAIL', {})
              resolve()
          }
      })
    })
  },
  getDrugItem({ commit }, d){
    return new Promise((resolve, reject) => {
      _API.getDrugItem(d).then((res)=>{
         
            if (res.code === 200 && res.data) {
              commit('SET_DATA_DETAIL', res.data.map((v,i)=>{
                  return {
                    ...v,
                    
                  }
              }))
          
              resolve(res)
           
          } else {
              commit('SET_DATA_DETAIL', {})
              resolve()
          }
      })
    })
  },
  getDrugFillNum({ commit }, d){
    return new Promise((resolve, reject) => {
      _API.getDrugFillNum(d).then((res)=>{
         
            if (res.code === 200 && res.data) {
              commit('SET_DATA_PEIYAO', res.data.map((v,i)=>{
                  return {
                    ...v,
                   }
              }))
          
              resolve(res)
           
          } else {
              commit('SET_DATA_PEIYAO', {})
              resolve()
          }
      })
    })
  },
  
  getStoreDrugNumShow({ commit }, d){
    return new Promise((resolve, reject) => {
      _API.getStoreDrugNumShow(d).then((res)=>{
         
            if (res.code === 200 && res.data) {
              commit('SET_DATA_KUCUN_DETAIL', res.data.map((v,i)=>{
                  return {
                    ...v,
                   }
              }))
          
              resolve(res)
           
          } else {
              commit('SET_DATA_KUCUN_DETAIL', {})
              resolve()
          }
      })
    })
  },

 
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

